package com.cjhhv.visual.service.impl;

import cn.hutool.core.util.StrUtil;
import com.cjhhv.base.util.PageUtil;
import com.cjhhv.visual.dao.DashboardThemeDao;
import com.cjhhv.visual.model.DashboardThemeModel;
import com.cjhhv.visual.service.DashboardThemeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional( rollbackFor = Exception.class)
public class DashboardThemeServiceImpl implements DashboardThemeService {

    private DashboardThemeDao dashboardThemeDao;

    public PageInfo<DashboardThemeModel> queryDashboardThemePageList(DashboardThemeModel parameter){
        return PageUtil.createPageQuery(parameter,()->this.dashboardThemeDao.queryDashboardThemePageList(parameter));
    }

    public int queryDashboardThemeIsExists(DashboardThemeModel parameter){
        return this.dashboardThemeDao.queryDashboardThemeIsExists(parameter);
    }

    public DashboardThemeModel queryDashboardThemeById(String dashboardId){
        return this.dashboardThemeDao.queryDashboardThemeById(dashboardId);
    }

    public int saveDashboardTheme(DashboardThemeModel parameter){
        if(StrUtil.isEmpty(parameter.getThemeId())){
            int count  = this.dashboardThemeDao.queryDashboardThemeIsExists(parameter);
            if(count<=0){
                return this.dashboardThemeDao.saveDashboardTheme(parameter);
            }else {
                return -1;
            }
        }else{
            return this.dashboardThemeDao.updateDashboardThemeById(parameter);
        }
    }

    public int updateDashboardThemeById(DashboardThemeModel parameter){
        return this.dashboardThemeDao.updateDashboardThemeById(parameter);
    }

    public int deleteDashboardThemeByIds(DashboardThemeModel parameter){
        return this.dashboardThemeDao.deleteDashboardThemeByIds(parameter);
    }
    public List<DashboardThemeModel> queryDashboardThemeList(){
        return this.dashboardThemeDao.queryDashboardThemeList();
    }


    public DashboardThemeDao getDashboardThemeDao() {
        return dashboardThemeDao;
    }

    @Autowired
    public void setDashboardThemeDao(DashboardThemeDao dashboardThemeDao) {
        this.dashboardThemeDao = dashboardThemeDao;
    }
}
